//
//  InitiatePlanDetailViewController.m
//  PlayBall
//
//  Created by yanxun on 8/27/14.
//
//

#import "InitiatePlanDetailViewController.h"
#import "SendSchemeOrderOperation.h"
@interface InitiatePlanDetailViewController ()<UIScrollViewDelegate,UITextFieldDelegate>{
    UIScrollView *_scrollView;
    NSMutableDictionary *_infoDic;
    
    UILabel *_issueLab;
    UILabel *_issueValue;
    UILabel *_endLab;
    UILabel *_endValue;
    
    UILabel *_moneyLab;
    UILabel *_moneyValue;
    
    UILabel *_bsLab;
    UITextField *_bsTextField;
    
    UILabel *_perLab;
    
    UIButton *_buyKindBtn;
    
    UILabel *_buyKindLab;
    
    UILabel *_perBonusLab;
    UILabel *_contentLab;
    
    
    CALayer *_layer0;
    CALayer *_layer1;
    CALayer *_layer2;
    CALayer *_layer3;
    CALayer *_lineLayer;
    NSMutableArray *_btnArr;
    NSInteger _bonusValue;
    
    CALayer *_layer4;
    UIButton *_sendBtn;
}

@end

@implementation InitiatePlanDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0f,SCREEN_WIDTH,self.view.frame.size.height)];
    _scrollView.directionalLockEnabled = YES; //只能一个方向滑动
    _scrollView.pagingEnabled = NO; //是否翻页
    _scrollView.showsVerticalScrollIndicator =YES; //垂直方向的滚动指示
    _scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滚动指示的风格
    _scrollView.showsHorizontalScrollIndicator = NO;//水平方向的滚动指示
    _scrollView.scrollEnabled = YES;
    _scrollView.delegate = self;
    CGSize newSize = CGSizeMake(self.view.frame.size.width, 568.0f);
    [_scrollView setContentSize:newSize];
    [self.view addSubview:_scrollView];
    
    _layer0 = [[CALayer alloc] init];
    _layer0.frame = CGRectMake(0.0f, 0.0f, 320.0f, 45.0f);
    _layer0.backgroundColor = UIColorRef(247,247,247).CGColor;
    
    
    //
    _issueLab = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 15.0f, 45, 14.0f)];
    _issueLab.text = @"期号：";
    _issueLab.backgroundColor = [UIColor clearColor];
    _issueLab.font = [UIFont systemFontOfSize:14.0f];
    
    
    _issueValue = [[UILabel alloc] initWithFrame:CGRectMake(_issueLab.frame.origin.x+_issueLab.frame.size.width, 15.0f, 90, 14.0f)];
    _issueValue.backgroundColor = [UIColor clearColor];
    _issueValue.textColor = UIColorRef(60, 154, 229);
    _issueValue.font = [UIFont systemFontOfSize:14.0f];
    

    _endLab = [[UILabel alloc] initWithFrame:CGRectMake(155.0f, 15.0f, 45.0f, 14.0f)];
    _endLab.backgroundColor = [UIColor clearColor];
    _endLab.font = [UIFont systemFontOfSize:14.0f];
    _endLab.text = @"截止：";
    
    
    _endValue = [[UILabel alloc] initWithFrame:CGRectMake(_endLab.frame.origin.x+_endLab.frame.size.width, 15, 120, 14.0f)];
    _endValue.backgroundColor = [UIColor clearColor];
    _endValue.font = [UIFont systemFontOfSize:14.0f];
    _endValue.textColor = UIColorRef(134.0f, 134.0f, 134.0f);
    
    
    _layer1 = [[CALayer alloc] init];
    _layer1.frame = CGRectMake(4.0f, 59.0f, 312.0f, 84.5f);
    //layer1.backgroundColor = UIColorRef(247,247,247).CGColor;
    //layer1.
    _layer1.borderWidth = 1;//设置边框的宽度，当然可以不要
    _layer1.borderColor = [UIColorRef(231, 231, 231) CGColor];//设置边框的颜色
    _layer1.masksToBounds = NO;//设为NO去试试
    //layer1.shadowOffset = CGSizeMake(.5,1);
    //layer1.shadowRadius = 1;
    //layer1.shadowColor = [UIColor blackColor].CGColor;
    //layer1.shadowOpacity = 0.3;
    //layer1.cornerRadius = 5;
    
    
    
    _lineLayer = [[CALayer alloc] init];
    _lineLayer.frame = CGRectMake(4.0f, 89.0f, 312.0f, 1.0f);
    _lineLayer.backgroundColor = UIColorRef(231,231,231).CGColor;
    
    
    
    
    _moneyLab = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 66.0f, 70.0f, 14.0f)];
    _moneyLab.backgroundColor = [UIColor clearColor];
    _moneyLab.font = [UIFont systemFontOfSize:14.0f];
    _moneyLab.text = @"方案金额：";
    
    
    //_moneyValue
    _moneyValue = [[UILabel alloc] initWithFrame:CGRectMake(_moneyLab.frame.origin.x+_moneyLab.frame.size.width, 66.0f, 100.0f, 14.0f)];
    _moneyValue.backgroundColor = [UIColor clearColor];
    _moneyValue.font = [UIFont systemFontOfSize:14.0f];
    
    //_bsLab
    _bsLab = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 105.0f, 70.0f, 14.0f)];
    _bsLab.backgroundColor = [UIColor clearColor];
    _bsLab.font = [UIFont systemFontOfSize:14.0f];
    _bsLab.text = @"我要认购：";
    
    _bsTextField = [[UITextField alloc ]initWithFrame:CGRectMake(_bsLab.frame.origin.x+_bsLab.frame.size.width, 100.0f, 72,29)];
    //_bsTextField.placeholder=@"密码";
    _bsTextField.returnKeyType=UIReturnKeyDone;
    _bsTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    //_bsTextField.secureTextEntry=YES;
    [self initTextField:_bsTextField withImageName:@"password"];
    
    
    //_perLab
    _perLab = [[UILabel alloc] initWithFrame:CGRectMake(_bsTextField.frame.origin.x+_bsTextField.frame.size.width, 105.0f, 100.0f, 14.0f)];
    _perLab.backgroundColor = [UIColor clearColor];
    _perLab.font = [UIFont systemFontOfSize:14.0f];
    
    //_buyKindBtn
    _buyKindBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _buyKindBtn.frame = CGRectMake(250.0f, 100.0f, 26, 26);
    _buyKindBtn.layer.borderWidth = 1.0f;
    _buyKindBtn.layer.borderColor = UIColorRef(231,231,231).CGColor;
    _buyKindBtn.layer.cornerRadius = 5.0f;
    _buyKindBtn.tag = 0;
    [_buyKindBtn addTarget:self action:@selector(buyKind:) forControlEvents:UIControlEventTouchUpInside];
    
    //_buyKindLab
    _buyKindLab = [[UILabel alloc] initWithFrame:CGRectMake(277.0f, 105.0f, 45.0f, 14.0f)];
    _buyKindLab.backgroundColor = [UIColor clearColor];
    _buyKindLab.font = [UIFont systemFontOfSize:14.0f];

    
    _perBonusLab = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 155.0f, 70.0f, 14.0f)];
    _perBonusLab.backgroundColor = [UIColor clearColor];
    _perBonusLab.font = [UIFont systemFontOfSize:14.0f];
    _perBonusLab.text = @"佣金比例：";
    

    _layer3 = [[CALayer alloc] init];
    _layer3.frame = CGRectMake(0.0f, 318.0f, 320.0f, 117.0f);
    _layer3.backgroundColor = UIColorRef(247,247,247).CGColor;
    _layer3.borderWidth = 1;
    _layer3.borderColor = UIColorRef(213,213,213).CGColor;
    
    
    _contentLab = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 330.0f, 70.0f, 14.0f)];
    _contentLab.backgroundColor = [UIColor clearColor];
    _contentLab.font = [UIFont systemFontOfSize:14.0f];
    _contentLab.text = @"内容：";
    
    
    _layer4 = [[CALayer alloc] init];
    _layer4.frame = CGRectMake(0.0f, 454.0f, 320.0f, 50.0f);
    _layer4.backgroundColor = UIColorRef(247,247,247).CGColor;
    _layer4.borderWidth = 1;
    _layer4.borderColor = UIColorRef(213,213,213).CGColor;
    
    
    _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _sendBtn.layer.borderWidth = 1;
    _sendBtn.layer.borderColor = [[UIColor colorWithRed:231.0f/255.0f green:231.0f/255.0f blue:231.0f/255.0f alpha:1.0f] CGColor];//设置边框的颜色
    _sendBtn.layer.masksToBounds = NO;
    _sendBtn.layer.cornerRadius = 5;
    _sendBtn.frame = CGRectMake(10, 463, 300, 35);
    
    
    //btn.backgroundColor = [UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f];
    
    [_sendBtn setTitle:@"立即发起" forState:UIControlStateNormal];
    //[btn setTitleColor:[UIColor colorWithRed:99.0f/255.0f green:99.0f/255.0f blue:99.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [_sendBtn.titleLabel setFont:[UIFont systemFontOfSize:12.0f]];
    [_sendBtn addTarget:self action:@selector(send:) forControlEvents:UIControlEventTouchUpInside];
    [_sendBtn setBackgroundColor:UIColorRef(250, 55, 66)];
    [_sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
}

- (void)buyKind:(id)sender{
    UIButton *btn = (UIButton *)sender;
    if (0 == btn.tag) {
        NSLog(@"图像");
        btn.tag = 1;
        [btn setImage:[UIImage imageNamed:@"jdd_check"] forState:UIControlStateNormal];
        [_bsTextField setText:[NSString stringWithFormat:@"%d",[[_moneyValue text] intValue]]];
        
    }else{
        NSLog(@"没有图像");
        btn.tag = 0;
        [btn setImage:nil forState:UIControlStateNormal];
        [_bsTextField setText:@"0"];
    }
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"DaiFaQiDingDan-detail"];

    [MobClick event:@"UserCenter-daifaqidingdan-detail"];

    [self setJddTabBarHidden:YES];
    [self getSchemeDetailRequest];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"DaiFaQiDingDan-detail"];
}
- (void)send:(id)sender{
    [self promptResInfo:@"功能尚在开发当中"];
    /*
    [_sendBtn setEnabled:NO];
    [self sendSchemeOrderRequest];
     */
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)sendSchemeOrderRequest{
    
    [JddCommonFunction setWaitingViewHidden:NO fromController:self];
    SendSchemeOrderOperation *operation = [[SendSchemeOrderOperation alloc] init];
    operation.delegate = self;
    operation.userId = [[JddGlobalParameter sharedInstance].dictionary objectForKey:GLOBAL_PARAMETER_USER_ID];
    operation.schemeId = self.schemeId;
    operation.buyShare = _bsTextField.text;
    operation.bonusScale = [NSString stringWithFormat:@"%d",_bonusValue];
    [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
}


//
- (void)SendSchemeOrderResult:(NSData *)result{
    [_sendBtn setEnabled:YES];
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if (result) {
        id info = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error:nil];
        //NSLog(@"%@",[info[@"Data"]objectFromJSONString]);
        NSDictionary *infoDic = [info[@"Data"]objectFromJSONString];
        NSLog(@"infoDic = %@",infoDic);
        [self promptResInfo:[infoDic objectForKey:@"Data"]];
    }
}


//获取待发起方案详情请求
- (void)getSchemeDetailRequest
{
    [JddCommonFunction setWaitingViewHidden:NO fromController:self];
    JddInitiatePlanDetailOperation *operation = [[JddInitiatePlanDetailOperation alloc] init];
    operation.delegate = self;
    operation.userId = [[JddGlobalParameter sharedInstance].dictionary objectForKey:GLOBAL_PARAMETER_USER_ID];
    operation.schemeId = self.schemeId;
    operation.dataSource = @"1";
    [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
    
}

//待发起方案详情服务器返回
- (void)JddInitiatePlanDetailResult:(NSData *)result
{
    
    [JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if (result) {
        id info = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",[info[@"Data"]objectFromJSONString]);
        NSDictionary *infoDic = [info[@"Data"]objectFromJSONString];
        /*
        if (!_infoDic) {
            _infoDic = [[NSMutableDictionary alloc] initWithDictionary:[info[@"Data"]objectFromJSONString]];
        }else{
            [_infoDic removeAllObjects];
            [_infoDic addEntriesFromDictionary:[info[@"Data"]objectFromJSONString]];
        }
        */
        
        self.title = [NSString stringWithFormat:@"%@待发起方案",[infoDic objectForKey:@"LottName"]];
        [_issueValue setText:[infoDic objectForKey:@"Issue"]];
        
        NSString *endTime = [infoDic objectForKey:@"BuyEndTime"];
        if ([endTime length]>16 ) {
            endTime = [endTime substringToIndex:16];
        }
        [_endValue setText:endTime];
        [_moneyValue setText:[NSString stringWithFormat:@"%@彩豆",[infoDic objectForKey:@"Money"]]];
        [_bsTextField setText:[NSString stringWithFormat:@"%@",[infoDic objectForKey:@"BS"]]];
        
        CGFloat per = [_bsTextField.text floatValue]/[_moneyValue.text floatValue];
        
        [_perLab setText:[NSString stringWithFormat:@"彩豆 占总额%0.f％",per*100]];
        /*
        if ([[infoDic objectForKey:@"IsJoinBuy"] integerValue] == 1) {
            //合买
            [_buyKindLab setText:@"合买"];
        }else{
            [_buyKindLab setText:@"自购"];
        }
        */
        [_buyKindLab setText:@"自购"];
        
        NSArray *array = nil;
        NSDictionary *lotNumber = [[infoDic objectForKey:@"LotNumber"] objectFromJSONString];
        //NSLog(@"lotNumber = %@",lotNumber);
        NSArray *itemArr = [lotNumber objectForKey:@"item"];
        NSInteger lotCount = 0;
        if ([itemArr count] > 0) {
            NSString *lotNumberStr = [[itemArr objectAtIndex:0] objectForKey:@"LotNumber"];
            lotCount = [[lotNumberStr componentsSeparatedByString:@"\n"] count];
            array = [lotNumberStr componentsSeparatedByString:@"\n"];
            for (int i = 0; i < [array count]; i++) {
                //NSLog(@"string:%@", [array objectAtIndex:i]);
            }
        }
        
        
        [_scrollView.layer addSublayer:_layer0];
        [_scrollView addSubview:_issueLab];
        [_scrollView addSubview:_issueValue];
        [_scrollView addSubview:_endLab];
        [_scrollView addSubview:_endValue];
        [_scrollView.layer addSublayer:_layer1];
        [_scrollView.layer addSublayer:_layer2];
        [_scrollView.layer addSublayer:_lineLayer];
        [_scrollView addSubview:_moneyLab];
        [_scrollView addSubview:_moneyValue];
        [_scrollView addSubview:_bsLab];
        [_scrollView addSubview:_bsTextField];
        [_scrollView addSubview:_perLab];
        [_scrollView addSubview:_buyKindBtn];
        [_scrollView addSubview:_buyKindLab];
        [_scrollView addSubview:_perBonusLab];
        [_scrollView.layer addSublayer:_layer3];
        [_scrollView addSubview:_contentLab];
        [_scrollView.layer addSublayer:_layer4];
        [_scrollView addSubview:_sendBtn];
        
        
        
        CGFloat BtnHeight = 30.0f;
        CGFloat BtnWidth = 65.0f;
        
        CGFloat offX = 18.0f;
        CGFloat offY = 180.0f;
        CGFloat offXWidth = 8.0f;
        CGFloat offYHeight = 15.0f;
        if (!_btnArr) {
            _btnArr = [[NSMutableArray alloc] init];
        }else{
            [_btnArr removeAllObjects];
        }
        
        NSArray *arr = [[NSArray alloc] initWithObjects:@"无",@"1％",@"2％",@"3％",@"4％",@"5％",@"6％",@"7％",@"8％",@"9％",@"10％",nil];
        //加载多个按钮
        for (NSInteger i=0; i<[arr count]; i++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.layer.borderWidth = 1;
            btn.layer.borderColor = [[UIColor colorWithRed:231.0f/255.0f green:231.0f/255.0f blue:231.0f/255.0f alpha:1.0f] CGColor];//设置边框的颜色
            btn.layer.masksToBounds = NO;
            btn.layer.cornerRadius = 5;
            btn.frame = CGRectMake(offX + (BtnWidth+offXWidth)*(i%4), offY+i/4*(BtnHeight+offYHeight), BtnWidth, BtnHeight);
            [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag = i;
            //btn.backgroundColor = [UIColor colorWithRed:247.0f/255.0f green:247.0f/255.0f blue:247.0f/255.0f alpha:1.0f];
            
            //[btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
            //[btn setTitleColor:[UIColor colorWithRed:99.0f/255.0f green:99.0f/255.0f blue:99.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
            [btn.titleLabel setFont:[UIFont systemFontOfSize:12.0f]];
            [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
            if ([[infoDic objectForKey:@"Bonus"] intValue] == i) {
                [btn setBackgroundColor:UIColorRef(250, 55, 66)];
                [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            }
            
            /*
             if (index == i) {
             btn.layer.borderColor = [[UIColor colorWithRed:250.0f/255.0f green:136.0f/255.0f blue:140.0f/255.0f alpha:1.0f] CGColor];//设置边框的颜色
             //_selectIndex = index;
             }
             */
            //[_floatLayer addSubview:btn];
            
            [_btnArr addObject:btn];
            [_scrollView addSubview:btn];
        }
        
        
        
        
        CGRect layer3Rect = _layer3.frame;
        CGFloat offX1 = 16.0f;
        CGFloat offY1 = 355.0f;
        CGFloat offWidthY = 12.0f;
        for (NSInteger i=0; i<[array count]; i++) {
            UILabel *lab1 = [[UILabel alloc] initWithFrame:CGRectMake(offX1, offY1+i*(offWidthY+14), 60, 14)];
            
            [lab1 setText:[NSString stringWithFormat:@"普通%@",[lotNumber objectForKey:@"PlayTypeName"]]];
            lab1.backgroundColor = [UIColor clearColor];
            lab1.textColor = UIColorRef(103, 103, 103);
            lab1.font = [UIFont systemFontOfSize:14.0f];
            [_scrollView addSubview:lab1];
            
            NSString *lotNum = [array objectAtIndex:i];
            NSString *lotRedNum = @"";
            NSString *lotBlueNum = @"";
            NSRange range = [lotNum rangeOfString:@"+"];
            if (range.location != NSNotFound) {
                lotRedNum = [lotNum substringToIndex:range.location];
                lotBlueNum = [lotNum substringFromIndex:range.location];
            }
            
            CGRect lab1Rect = lab1.frame;
            UILabel *lab2 = [[UILabel alloc] initWithFrame:CGRectMake(lab1Rect.origin.x+lab1Rect.size.width, offY1+i*(offWidthY+14), 130, 14)];
            [lab2 setText:[NSString stringWithFormat:@": %@",lotRedNum]];
            lab2.backgroundColor = [UIColor clearColor];
            lab2.textColor = UIColorRef(103, 103, 103);
            lab2.font = [UIFont systemFontOfSize:14.0f];
            [_scrollView addSubview:lab2];
            
            CGRect lab2Rect = lab2.frame;
            
            UILabel *lab3 = [[UILabel alloc] initWithFrame:CGRectMake(lab2Rect.origin.x+lab2Rect.size.width, offY1+i*(offWidthY+14), 50, 14)];
            [lab3 setText:[NSString stringWithFormat:@"%@",lotBlueNum]];
            lab3.backgroundColor = [UIColor clearColor];
            lab3.textColor = UIColorRef(103, 103, 103);
            lab3.font = [UIFont systemFontOfSize:14.0f];
            [_scrollView addSubview:lab3];
            
        }
        layer3Rect.size.height = 35.0f + 26*lotCount;
        _layer3.frame = layer3Rect;
        
        
        CGRect layer4Rect = _layer4.frame;
        layer4Rect.origin.y = _layer3.frame.origin.y + _layer3.frame.size.height + 20;
        _layer4.frame = layer4Rect;
        
        CGRect sendBtnRect = _sendBtn.frame;
        sendBtnRect.origin.y = _layer4.frame.origin.y + 7;
        _sendBtn.frame = sendBtnRect;
        
        /*
        [_scrollView.layer addSublayer:_layer4];
        [_scrollView addSubview:_sendBtn];
         */
    }
}

- (void)click:(id)sender{
    UIButton *btn = (UIButton *)sender;
    for (id view in _btnArr) {
        [view setBackgroundColor:[UIColor clearColor]];
        [view setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    [btn setBackgroundColor:UIColorRef(250, 55, 66)];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _bonusValue = btn.tag;
}

-(void)initTextField:(UITextField *)fieldName  withImageName:(NSString *)str
{
    fieldName.delegate=self;
    fieldName.returnKeyType=UIReturnKeyDone;
    fieldName.backgroundColor=[UIColor whiteColor];
    fieldName.layer.borderWidth = 1;//设置边框的宽度，当然可以不要
    fieldName.layer.borderColor = [UIColorRef(231, 231, 231) CGColor];//设置边框的颜色
    fieldName.layer.cornerRadius = 5;
    //fieldName.clearsOnBeginEditing=YES;
    //fieldName.clearButtonMode = UITextFieldViewModeWhileEditing;
    //fieldName.clearButtonMode=YES;
    fieldName.font=[UIFont systemFontOfSize:14];
    fieldName.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    
    //不让uitextfield字体挨着边框,UITextField 的左边加view
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 29)];
    imgView.image=[UIImage imageNamed:str];
    fieldName.leftView=imgView;//UITextField 的左边view
    fieldName.leftViewMode=UITextFieldViewModeAlways;//UITextField 的左边view 出现模式
}

#pragma mark-TextField delegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    //  判断输入的是否为数字 (只能输入数字)
    NSLog(@"textField.text = %@    ",textField.text);
    NSLog(@"string = %@\n",string);
    NSString *validRegEx =@"^[0-9]*$";
    
    NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", validRegEx];
    
    BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:string];
    
    
    
    if (myStringMatchesRegEx){
        
        if (([textField.text integerValue] > [_moneyValue.text integerValue])) {
           
            return NO;
        }
        
        if ([string length] > 0) {
            //不是删除
            NSString *textContent = [NSString stringWithFormat:@"%@%@",textField.text,string];
            if (textContent && ([textContent integerValue] > [_moneyValue.text integerValue])) {
                return NO;
            }
        }
        
        if ([string intValue] > [_moneyValue.text integerValue]) {
            return NO;
        }
        return YES;
    }else{
        return NO;
    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)promptResInfo:(NSString *)infoString
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] init];
    [hud setMode:MBProgressHUDModeText];
    hud.detailsLabelText = infoString;
    hud.detailsLabelFont = [UIFont systemFontOfSize:15];
    [self.view addSubview:hud];
    [hud show:YES];
    hud.margin = 10.f;
    hud.yOffset = -30.f;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1.0];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
